<?php

namespace IMT\EventBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;


class DefaultController extends Controller
{
    public function indexAction($id)
    {
    	$repository = $this->getDoctrine()->getRepository('IMTEventBundle:Event');
    	 
    	$eventObject = $repository->findOneById($id);
    	
    	$comments = $eventObject->getComments();
    	$participants = $eventObject->getParticipants();
    	$owner = $participants[0]->getParticipant()->getPerson();
    	
    	$arrayRender = array(
    							"title" => $eventObject->getTitle(), 
    							"date" => $eventObject->getDate(), 
    							"id" => $eventObject->getId(), 
    							"number_comment" => count($comments),
    							"number_participant" => count($participants),
    							"owner" => $owner
    						);
    	
       return $this->render('IMTEventBundle:Default:event.html.twig', $arrayRender);
    }
    
    public function loadEventContentAction($id)
    {
    	if(empty($id)){
    		// TODO
    	}    	
    	
    	$repository = $this->getDoctrine()->getRepository('IMTEventBundle:Event');
    	$eventObject = $repository->findOneById($id);
    	
    	/*if(empty($eventObject->getId())){
    		// TODO
    	}*/ 
    	
    	$arrayRender = array("content" => $eventObject->getContent());

    	return $this->render('IMTEventBundle:Event:event.html.twig', $arrayRender);
    }
}


